﻿using AnlianCommon.Common.Domains.BankCustomers;
using AnlianCommon.Common.DTO;
using AnlianCommon.Common.Infrastructure.IRepository;
using AnlianCommon.Enum;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace SheepCommon.API.Vendors
{
    public class ClientsBackFillHandler : IRequestHandler<ClientsBackFillCommand, Result>
    {
        private readonly IBaseRepository<Client> _clientRepository;

        public ClientsBackFillHandler(IBaseRepository<Client> clientRepository)
        {
            _clientRepository = clientRepository;
        }
        /// <summary>
        /// 客户信息反填业务逻辑
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(ClientsBackFillCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code=(int)CommonErrorCode.Search};
            try
            {
                var clientsBackFill = await (await _clientRepository.GetAll()).Where(c => c.ClientId == request.ClientId).FirstOrDefaultAsync();
                if (clientsBackFill != null)
                {
                    result.Data = clientsBackFill;
                }

            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
